# $Id$
# Maintainer: Rémy Oudompheng <remy@archlinux.org>

pkgname=texlive-langjapanese
pkgver=2018.48562
_revnr=${pkgver#2018.}
pkgrel=1
pkgdesc="TeX Live - Fonts and macro packages to typeset Japanese texts"
license=('GPL')
arch=(any)
depends=('texlive-core')
groups=('texlive-lang')
url='http://tug.org/texlive/'
source=("https://sources.archlinux.org/other/texlive/$pkgname-$pkgver-src.zip"
        "$pkgname.maps"
        "$pkgname.fmts")
options=('!emptydirs')
sha256sums=('02399ae278ad70671fd949fdd73e66ef2b506df3c9a6698b0b8c9ae7acb5f6f4'
            '0ed1679f0bfd7a2afcac173cbb15da95672a24479a8c7ba9ec20222449394601'
            'd81d467f9c1963330e1af03d50eda43cbc12d29f3644beec5165de4fd3e4cf3b')

build() {
   cd "$srcdir"
   for p in *.tar.xz; do
	   bsdtar -xf $p
   done
   rm -rf tlpkg
}

package() {
   install -m755 -d $pkgdir/var/lib/texmf/arch/installedpkgs
   sed -i '/^#/d' CONTENTS
   install -m644 CONTENTS $pkgdir/var/lib/texmf/arch/installedpkgs/${pkgname}_${_revnr}.pkgs
   install -m644 $pkgname.maps $pkgdir/var/lib/texmf/arch/installedpkgs/
   install -m644 $pkgname.fmts $pkgdir/var/lib/texmf/arch/installedpkgs/
   install -m755 -d $pkgdir/usr/share
   wanteddirs=$(for d in *; do test -d $d && [[ $d != texmf* ]] && echo $d; done) || true
   for dir in $wanteddirs; do
     find $dir -type d -exec install -d -m755 $pkgdir/usr/share/texmf-dist/'{}' \;
     find $dir -type f -exec install -m644 '{}' $pkgdir/usr/share/texmf-dist/'{}' \;
   done
   if [[ -d texmf-dist ]]; then
     find texmf-dist -type d -exec install -d -m755 $pkgdir/usr/share/'{}' \;
     find texmf-dist -type f -exec install -m644 '{}' $pkgdir/usr/share/'{}' \;
   fi
   if [[ -d $pkgdir/usr/share/texmf-dist/scripts ]]; then
     find $pkgdir/usr/share/texmf-dist/scripts -type f -exec chmod a+x '{}' \;
   fi

    # scripts links
    _linked_scripts="
convbkmk/convbkmk.rb
ptex2pdf/ptex2pdf.lua
ptex-fontmaps/kanji-config-updmap.pl
ptex-fontmaps/kanji-config-updmap-sys.sh
ptex-fontmaps/kanji-config-updmap-user.sh
ptex-fontmaps/kanji-fontmap-creator.pl
"
    install -m755 -d $pkgdir/usr/bin
    for _script in ${_linked_scripts}; do
        _scriptbase=$(basename $_script)
        _scriptbase=${_scriptbase%.*}
        ln -s /usr/share/texmf-dist/scripts/${_script} ${pkgdir}/usr/bin/${_scriptbase}
    done
}
